import {dataBookApi, institutionsApi, jhApi, OutsideDoctorApi, ygxxApi} from "./basic";
// import React from "react";
import {
    CameraOutlined,
    InboxOutlined,
    IdcardOutlined,
    // IdcardOutlined
    VideoCameraOutlined,
    // IdcardOutlined,
    MenuOutlined,
    CarryOutOutlined,
    MedicineBoxOutlined,
    UsergroupAddOutlined,
    UserOutlined,
    SolutionOutlined,
    ContactsOutlined,
    DeploymentUnitOutlined
} from "@ant-design/icons";

/**
 * 全局数据字典，相同接口数据，仅请求一次。
 * */
class Dictionary {
    // 公司名称
    static companies = [];

    static getCompanies() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.companies || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                institutionsApi.search({search: ""}).then(res => {
                    const oldList = res["records"] || [];
                    const list = [];
                    oldList.forEach(item => {
                        // yybm:"20000000000000001"
                        // yymc:"鹏成车邦总部"
                        list.push({
                            value: item.yybm,
                            label: item.yymc
                        })
                    })
                    Dictionary.companies = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 跟进状态
    static followState = [];

    static getFollowState() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.followState || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                // {zdlxdmIN: "83,84,85", ztbz: 1,}
                // 82:职务，83:跟进状态、84:联系来源、85:项目  sjzds
                dataBookApi.getByDm({zdlxdmIN: "83", ztbz: 1,}).then(res => {
                    const oldList = res.data[0].sjzds || [];
                    const list = [];
                    // sjbm:"04"
                    // sjbz:"BLUE"
                    // sjlx:"83"
                    // sjmc:"预约未到店"
                    oldList.forEach(item => {
                        list.push({
                            value: item.sjbm,
                            text: item.sjmc,
                            label: item.sjmc
                        })
                    })
                    Dictionary.followState = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 联系来源
    static channel = [];

    static getChannel() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.channel || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                // {zdlxdmIN: "83,84,85", ztbz: 1,}
                // 83:跟进状态、84:联系来源、85:项目  sjzds
                dataBookApi.getByDm({zdlxdmIN: "84", ztbz: 1,}).then(res => {
                    const oldList = res.data[0].sjzds || [];
                    const list = [];
                    // sjbm:"1"
                    // sjlx:"84"
                    // sjmc:"抖音视频获取"
                    oldList.forEach(item => {
                        list.push({
                            value: item.sjbm,
                            label: item.sjmc
                        })
                    })
                    Dictionary.channel = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 意向项目
    static projects = [];

    static getProjects() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.projects || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                dataBookApi.getByDm({zdlxdmIN: "85", ztbz: 1,}).then(res => {
                    const oldList = res.data[0].sjzds || [];
                    const list = [];
                    oldList.forEach(item => {
                        list.push({
                            value: Number(item.sjbm),
                            label: item.sjmc
                        })
                    })
                    Dictionary.projects = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 删除原因
    static delReason = [];

    static getDelReason() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.delReason || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                dataBookApi.getByDm({zdlxdmIN: "86", ztbz: 1,}).then(res => {
                    console.log("1234")
                    console.log(res)
                    const oldList = res.data[0].sjzds || [];
                    const list = [];
                    oldList.forEach(item => {
                        list.push({
                            value: Number(item.sjbm),
                            label: item.sjmc
                        })
                    })
                    Dictionary.delReason = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 人员列表
    static person = [];

    static getPerson(params = {}) {
        return new Promise(resolve => {
            const sessionVal = Dictionary.person || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                ygxxApi.search({search: "", ...params}).then(res => {
                    const oldList = res["records"] || [];
                    const list = [];
                    oldList.forEach(item => {
                        list.push({
                            value: item.gh,
                            label: item.xm
                        })
                    })
                    Dictionary.person = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 核对状态
    static checkState = [
        // [{xm:'未核对',id:0}, {xm:'已核对',id:1}, {xm:'核对有误',id:2}],
        {value: 0, label: "未核对"},
        {value: 1, label: "已核对"},
        {value: 2, label: "核对有误"},
    ];

    static getCheckState() {
        return new Promise(resolve => {
            resolve(Dictionary.checkState);
        })
    }

    // 职位
    static positions = [];

    static getPositions() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.positions || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                dataBookApi.getByDm({zdlxdmIN: "82", ztbz: 1,}).then(res => {
                    const oldList = res.data[0].sjzds || [];
                    const list = [];
                    oldList.forEach(item => {
                        list.push({
                            value: item.sjbm,
                            label: item.sjmc
                        })
                    })
                    Dictionary.positions = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 账号
    static accounts = []

    static getAccounts() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.accounts || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                OutsideDoctorApi.search({search: ""}).then(res => {
                    const oldList = res["records"] || [];
                    const list = [];
                    oldList.forEach(item => {
                        // czsj:"2025-06-12 15:07:43"
                        // hzxm:"高德地图"
                        // czsj:"2025-06-12 15:07:43"
                        // hzxm:"高德地图"
                        // ok:true
                        // sfzh:"11111111112"
                        // wzyymc:"20000000000000001"
                        // ztbz:"1"
                        // ztbzmc:"有效"
                        list.push({
                            value: item.sfzh,
                            label: item.hzxm
                        })
                    })
                    Dictionary.accounts = list || [];
                    resolve(list);
                })
            }
        })
    }

    // 计划页面用到的账号
    static jhAccounts = []

    static getJhAccounts() {
        return new Promise(resolve => {
            const sessionVal = Dictionary.jhAccounts || [];
            if (sessionVal && sessionVal.length) {
                resolve(sessionVal);
            } else {
                jhApi.search({search: "", size: 10000, current: 1}).then(res => {
                    const oldList = res.data["records"] || [];
                    const list = [];
                    oldList.forEach(item => {
                        list.push({
                            value: item.zhid,
                            label: item.zhmc
                        })
                    })
                    Dictionary.jhAccounts = list || [];
                    resolve(list);
                })
            }
        })
    }

    static validity = {
        1: "有效",
        0: "无效",
        2: "三天内重复",
        4: "有效，三天内重复",
        3: "全部"
    }

    // 公司成交情况、审核统计，两个页面用到
    // 双击row是查看详情弹窗的table参数（接口selectPagecj）
    static dealColumns = [
        {
            title: '留资编号',
            dataIndex: 'lzbh',
        },
        {
            title: '公司名称',
            dataIndex: 'yymc',
        },
        {
            title: '来源账号',
            dataIndex: 'hzxm',
        },
        {
            title: '跟进状态',
            dataIndex: 'gjztmc',
            onFilter: (value, record) => Number(record.gjzt) === Number(value)
        },
        {
            title: '客服/销售',
            dataIndex: 'kfxm',
        },
        {
            title: '成交金额',
            dataIndex: 'cjje',
            // minWidth: 180,
        },
        {
            title: '联系方式',
            dataIndex: 'lxfs',
        },
        {
            title: '车型',
            dataIndex: 'cx',
        },
        {
            title: '创建时间',
            dataIndex: 'cjsj',
        },
        {
            title: '进店日期',
            dataIndex: 'jdrq',
        },
        {
            title: '到店间隔',
            tip:'进店日期-创建日期=到店间隔（天数）',
            dataIndex: 'ddjg',
        },
        {
            title: '成交日期',
            dataIndex: 'cjrq',
        },
        {
            title: '导购',
            dataIndex: 'dgmc',
        },
        {
            title: '到店公司',
            dataIndex: 'dgmc',
            render(_, record) {
                // 跟进状态gjzt：3预约、5、6到店，10、11异店
                // 01,02,03,04,05,06,07,08,10,11
                // 等待跟进,已经联系,已经预约,预约未到店,到店未成交,到店已成交,他人已成交,跟进被删除,异公司到店,异公司成交
                // ygsmc
                return [10, 11].includes(record.gjzt) ? record.ygsmc : record.yymc
            },
            excelRender: (_, record) => [10, 11].includes(record.gjzt) ? record.ygsmc : record.yymc
        },
        {
            title: '施工项目',
            dataIndex: 'sgxm',
        },
        {
            title: '留资时段',
            tip:"白天：17:30之前，晚上：17:30之后",
            dataIndex: 'sjlx',
        },
        {
            title: '核对状态',
            dataIndex: 'jz',
            render(text) {
                return ["未核对", "已核对", "核对有误"][Number(text)]
            }
        },
    ];

    // 响应状态，对应的颜色：0 正常绿色 1橙色 2红色 3灰色
    // static responseColors = ["green", "orange", "red", "gray"];
    static responseColors = ["#008000", "#ffa500", "#ff0000", "#808080"];

    // 平台
    static platform = {
        1: "抖音",
        2: "小红书",
        3: "短视频",
        4: "美团",
        5: "高德",
        0: "其他",
    };

    // 拍摄项目，相较于留资的意向项目，多了音响，且直接传中文
    // static shootProjects= ["大屏", "360", "通风", "灯光", "氛围灯", "音响", "其他"];

    // 拍摄状态
    static shootStates = ["作废", "已拍摄", "已剪辑", "已发布"];

    // icons 主要用于slider的menu动态Icon，原写法会全量引入Icon包
    static icons = {
        CameraOutlined,
        InboxOutlined,
        IdcardOutlined,
        VideoCameraOutlined,
        MenuOutlined,
        CarryOutOutlined,
        MedicineBoxOutlined,
        UsergroupAddOutlined,
        UserOutlined,
        SolutionOutlined,
        ContactsOutlined,
        DeploymentUnitOutlined
    }
}

export default Dictionary;
